<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:a4j="http://richfaces.org/a4j"
      xmlns:fn="http://java.sun.com/jsp/jstl/functions"
      xmlns:rich="http://richfaces.org/rich">

    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <div class="tituloPagina">
                <h:graphicImage value="/LaCruz_v2/faces/javax.faces.resource/img/report-icon.png" />
                <h:outputText value="#{bundle.ListItemPedidoClienteTitle}" style="padding-left: 10px" ></h:outputText>
            </div>
        </ui:define>

        <ui:define name="body">
            <h:form styleClass="jsfcrud_list_form" id="formJSF" target="_blank" >

                <h:panelGroup id="messagePanel" layout="block">
                    <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
                </h:panelGroup>
                <h:outputText escape="false" value="#{bundle.ListItemPedidoClienteEmpty}" rendered="#{itemPedidoController.pedidos.rowCount == 0}"/>
                <h:panelGroup rendered="#{itemPedidoController.pedidos.rowCount > 0}" style="text-align: center">
                    <rich:dataTable rowKeyVar="row" id="tablePedido" value="#{itemPedidoController.pedidos}" var="item"  rowClasses="jsfcrud_odd_row,jsfcrud_even_row" rendered="true"  style="border:solid 0px">
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_produto}"/>
                            </f:facet>
                            <h:graphicImage value="#{item.produto.caminhoImagem}" width="75" height="75"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_colecao}"/>
                            </f:facet>
                            <h:outputText value="#{item.produto.colecao.descricao}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_produto}"/>
                            </f:facet>
                            <h:outputText value="#{item.produto.descricao}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_tamanho}"/>
                            </f:facet>
                            <h:outputText value="#{item.produto.tamanho.descricao}"/>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_qtd}"/>

                            </f:facet>
                            <h:panelGrid columns="3">
                                <a4j:commandLink action="#{buyManager.remove(item.produto)}" value="-" onmouseout="$('#item_quant_#{row+ 1}').val(#{item.qtd});" >
                                    <f:ajax  event="click" execute="@this" immediate="true" render=":carrinho tablePedido" />
                                </a4j:commandLink>
                                <h:outputText id="quantidade" value="#{item.qtd}"/>
                                <a4j:commandLink action="#{buyManager.add(item.produto)}" value="+" onmouseout="$('#item_quant_#{row+ 1}').val(#{item.qtd});">
                                    <f:ajax  event="click" execute="@form" immediate="true" render=":carrinho tablePedido " />
                                </a4j:commandLink>
                            </h:panelGrid>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_precoUnitario}"/>
                            </f:facet>
                            <h:outputText value="#{item.produto.valorUnitario}">
                                <f:convertNumber pattern="R$####.00" />
                            </h:outputText>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListItemPedidoTitle_precoTotal}"/>
                            </f:facet>
                            <h:outputText value="#{item.qtd * item.produto.valorUnitario}">
                                <f:convertNumber pattern="R$####.00" />
                            </h:outputText>
                        </rich:column>
                        <rich:column>
                            <f:facet name="header">
                                <h:outputText value="&nbsp;"/>
                            </f:facet>
                            <h:commandLink action="#{itemPedidoController.removePedido(item)}" >
                                <h:graphicImage value="#{bundle.ListItemPedidoDestroyPedidoLink}" />
                            </h:commandLink>
                        </rich:column>


                    </rich:dataTable>
                </h:panelGroup>

                <h:panelGrid styleClass="buttonStyle" rendered="#{buyManager.existePedido}">
                      <h:commandLink rendered="#{buyManager.existePedido}" action="#{itemPedidoController.createPedidos}" value="#{bundle.CreatePedidoSaveClienteLink}" >
                      </h:commandLink>
                </h:panelGrid>


            </h:form>
        </ui:define>
    </ui:composition>

</html>
